package com.example.zxw

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import com.example.zxw.test.TestAop
import com.example.zxw.test.TestKotlinAnnotation
import com.example.zxw.test.TestKotlinAop
import com.fmt.mvi.learn.gobal.log
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.gyf.immersionbar.ImmersionBar

class ZxwMainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_zxw_main)

        initTabMinWidthHacking()
        ImmersionBar.with(this).transparentBar().init()
        val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottom_nav)
        val navHostFragment =
            supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
        val navController = navHostFragment.navController
        bottomNavigationView.setupWithNavController(navController)
        bottomNavigationView.itemIconTintList = null
        //测试aop，java和kotlin环境测试
        TestAop().testAopMethod()
        TestKotlinAop().testAop2()
        TestKotlinAnnotation.test()
    }





    //在调用 ScrollableTabRow 前调用 init 方法。
    private fun initTabMinWidthHacking() {
        try {
            hackTabMinWidth()
        } catch (e: Exception) {
            e.printStackTrace()
            e.log()
        }
    }

    // ScrollableTab内部设置了单个 tab 的最小宽度 ScrollableTabRowMinimumTabWidth 为90，且属性无法自定义
    // https://issuetracker.google.com/issues/218684743 (Won't Fix)
    private fun hackTabMinWidth() {
        val clazz = Class.forName("androidx.compose.material3.TabRowKt")
        val field = clazz.getDeclaredField("ScrollableTabRowMinimumTabWidth")
        field.isAccessible = true
        field.set(null, 0.0f) // set tab min width to 0
    }
}
